<?php
/**
 * @author writethesky <writethesky@163.com>
 */

$iinfo = getimagesize($destination);



switch ($iinfo[2]) {
    case 1 :
        $simage = imagecreatefromgif($destination);
        imageAlphaBlending($simage, true);
		imageSaveAlpha($simage, true);
        break;
    case 2 :
        $simage = imagecreatefromjpeg($destination);
        break;
    case 3 :
        $simage = imagecreatefrompng($destination);
        imageAlphaBlending($simage, true);
		imageSaveAlpha($simage, true);
        break;
    case 6 :
        $simage = imagecreatefromwbmp($destination);
        break;
    default :
        die("不支持的文件类型");
        exit;
}

switch ($config['WATERTYPE']) {
    case 1 : //加水印字符串
    	$black = imagecolorallocate($simage, 0, 0, 0);
        imagestring($simage, 2, 3, $iinfo[1] - 15, $config['WATERSTRING'], $black);
        break;
    case 2 : //加水印图片
        $simage1 = imagecreatefrompng($config['WATERIMG']);
        $water_size = getimagesize($config['WATERIMG']);
        if($water_size[1]*3 >= $iinfo[1]){
        	break;
        }
        imagecopy($simage, $simage1, 0, $iinfo[1]-$water_size[1], 0, 0, $water_size[0], $water_size[1]);
        imagedestroy($simage1);
        break;
}
switch ($iinfo[2]) {
    case 1 :
        //imagegif($nimage, $destination);
        imagejpeg($simage, $destination);
        break;
    case 2 :
        imagejpeg($simage, $destination);
        break;
    case 3 :
        imagepng($simage, $destination);
        break;
    case 6 :
        imagewbmp($simage, $destination);
        //imagejpeg($nimage, $destination);
        break;
}
//覆盖原上传文件
imagedestroy($simage);